﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;

namespace THO7_Team8.Filters
{
    class imYellow : VisionAlgorithm
    {
        public imYellow(String name) : base(name) { }
        public override System.Drawing.Bitmap DoAlgorithm(System.Drawing.Bitmap sourceImage)
        {
            Bitmap returnImage = new Bitmap(sourceImage);

            // Lock the bitmap's bits.  
            Rectangle rect = new Rectangle(0, 0, returnImage.Width, returnImage.Height);
            BitmapData bmpData =
                returnImage.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite,
                PixelFormat.Format24bppRgb);

            ///////////////////////////////////////////////////////////
            unsafe
            {
                int pixelSize = 3;
                for (int y = 0; y < bmpData.Height; y++)
                {
                    byte* row = (byte*)bmpData.Scan0 + (y * bmpData.Stride);
                    for (int x = 0; x < bmpData.Width; x++)
                    {
                        unchecked
                        {
                            byte BlackaVlakka = (byte)0x000000;
                            byte blackpicks = (byte)0x00000f;
                            byte WittaVlakka = (byte)0xff0000;
                            if ((byte)row[x * pixelSize] >= blackpicks)
                            {
                                row[x * pixelSize] = BlackaVlakka;
                            }
                            else
                                row[x * pixelSize] = WittaVlakka;
                        }

                    }
                }
            }


            // Unlock the bits.
            returnImage.UnlockBits(bmpData);

            return returnImage;
        }

    }
}
